#{extends 'main.html' /}
#{set title:'Browse Registration' /}

<form id ="form" action="@{Application.browse_registration()}" method="POST">
    Select a student <select size="1" name="student_id" id = "s_id" onchange="this.form.submit()"> 
                <option value="">--</option>
            #{list items:models.Student.findAll(), as:'su'}
                #{if su.id == student_id}
                <option selected="selected" value="${su.id}">${su.getName()}</option>
                #{/if}
                #{else}
                 <option value="${su.id}">${su.getName()}</option>
                #{/else}
            #{/list}
           </select> 

</form>
<br>

#{if student_id != null}

<table border="1">
<tr>
<th>reg_ID</th>
<th>Student</th>
<th>Teacher</th>
<th>Course</th>
<th>Registration Date</th>
<th>Access</th>
<th>Delete</th>

</tr>

 #{list items:regs, as:'r'}
  <tr>
  	<td>${r.id}</td>
 	<td>${r.student.getName()}</td>
 	<td>${r.teacher.name}</td>
 	<td>${r.course.name+ " - "+r.course.activity.name}</td>
 	<td>${r.registrationDate}</td>
 	<td><form action="@{Application.view_registration()}" method="POST">
 		<input type="hidden" name="registration_id" value="${r.id}">
 		<input type="submit" value="View">
 	</form>
 	</td>
 	<td><form action="@{Application.delete_registration()}" method="POST">
 		<input type="hidden" name="reg_id" value="${r.id}">
 		<input type="hidden" name="student_id" value="${student_id}">
 		<input type="submit" value="Delete" class="delete" disabled="disabled">
 	</form>
 	</td>
 </tr>
                
 #{/list}

</table>
<br>
<button>Enable Deletion</button>

#{/if}


<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $(".delete").removeAttr("disabled");
  });
});
</script>

